home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: openDisk.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:38 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "sysdefs.h"
- #include <sys/stat.h>
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "bf.h"
- #include "volume.h"
- #include "pool.h"
- #include "threadstate.h"
- #include "thread_globals.h"
- #include "disk_funcs.h"
- #include "msg_globals.h"
- #include "queue_consist.h"
- #include "io_globals.h"
-
-
- static BOOL
- checkForRaw(VOLREC *const volRec, const BOOL couldBeEmpty)
- {
- struct stat statInfo;
-
- /*
- * See if the named file is a raw disk
- */
- if (stat(volRec->volNameRec->volName.name, &statInfo) < 0) {
- SM_ERROR(TYPE_SYS, errno);
- return FALSE; /* not ok */
- }
- /* if it's not a character device, its not a raw disk */
- if ((statInfo.st_mode & S_IFMT) != S_IFCHR) {
- volRec->volflags &= ~VOL_RAWDEV;
- } else {
- volRec->volflags |= VOL_RAWDEV;
- }
-
- if(couldBeEmpty)
- return TRUE; /* ok */
-
- if( statInfo.st_size < sizeof(VOLHDR) && !(volRec->volflags & VOL_RAWDEV)) {
- /* catch this before we try to read the header */
- /* note that st_size is 0 for raw devices */
- SM_ERROR(TYPE_USER, esmBADVOLHEADER);
- return FALSE; /* not ok */
- }
- return TRUE; /* ok */
- }
-
-
- BOOL
- openDisk (
- const char *const diskName,
- const BOOL forFormat,
- VOLREC *const volRec
- )
-
- {
- FLAGS flags;
- DISKMSG *message = Active->diskMessage;
-
- TRPRINT(TR_DISK, TR_LEVEL_1, ("opening disk:%s", diskName));
- SM_ASSERT(LEVEL_1, (message!=NULL));
-
- SM_ASSERT(LEVEL_1, volRec->volLink == NULL);
-
- if(forFormat)
- flags = O_CREAT | O_TRUNC;
- else
- flags = NOFLAGS;
-
- /*
- * fork disk process. But, don't fork it if we're only doing
- * fastPath (e.g. formatvol is running or we're pre-mounting
- * devices.)
- */
- if (FastPathOnly == FALSE) {
- /*
- * Open the file to see if there's any reason not to
- * fork a process for this volume.
- */
- int fd;
-
- if((fd = open(diskName, flags, 0604)) < 0){
- fprintf(sm_ErrorStream, "%s: ", diskName);
- SM_ERROR(TYPE_SYS, errno);
- /* no go */
- return FALSE;
- }
- close(fd);
- TRPRINT(TR_DISK, TR_LEVEL_1, ("disk:%s is open-able", diskName));
-
- if (forkDiskProc(volRec) != esmNOERROR) {
- /* no go */
- return FALSE;
- }
- }
-
- /*
- * setup the open message
- */
- message->header.type = OPEN_DISK;
- message->body.flags = flags;
-
- /*
- * send the message
- */
- if (callDisk(volRec, message)) {
- /* callDisk returns esmNOERROR or an error # */
- return FALSE;
-
- }
- /* ok ... opened it fine */
-
- return checkForRaw(volRec, forFormat); /* TRUE if ok; FALSE if not ok */
- }
-